Repository navigation
fix(instance): reopening a route while it pops reuses a disposed controller - #3491
Open
MikaelDDavidd wants to merge 1 commit into
Open
MikaelDDavidd wants to merge 1 commit into
MikaelDDavidd wants to merge 1 commit into
Conversation
…roller Going back and opening the same route again before the pop transition finished left the new page with the old controller. The old route's dispose then deleted the controller the new page was using, so things like its TextEditingController failed after dispose. Two things caused it: - GetObserver.didPop didn't mark the popped route's dependencies as dirty (didRemove and didReplace already do), so the binding of the reopened route kept the old instance instead of registering a new one. - delete() only picked the replaced instance (lateRemove) when the current entry was dirty, which is never the case after a replacement. It deleted the new instance and leaked the old one. Fixes jonataslaw#3446
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3446
Also looks like the same thing reported in #1880.
If you go back from a page and open the same route again before the pop transition ends, the new page ends up with a controller that is already closed and no longer registered. Anything that touches it after that (its TextEditingController,
Get.find, etc.) breaks. If you wait for the transition to finish, it works fine.Two things cause it, and both need fixing:
GetObserver.didPopdoesn't callreportRouteWillDisposefor the popped route.didRemoveanddidReplacealready do. Without it the dependency isn't marked dirty, so the binding of the reopened route keeps the old instance instead of registering a new one.delete()only useslateRemovewhen the current entry is dirty. After a dirty entry gets replaced, the new entry is never dirty, so the old route's dispose deletes the new instance (the one the page is using) and the old one is never closed.I changed
didPopto do the same asdidRemove, anddelete()to uselateRemovewhenever it's set. Thedelete()part is the same change #2421 proposed back in 2022, for a file that no longer exists on master. I tried each change on its own and the new tests still fail with only one of them.To check it in a real app I built the code from the issue for web with Flutter 3.47.8, once against master and once against this branch. Two changes to the issue code:
BindingsBuilderdoesn't exist on master anymore so I used a smallBindingsclass, and I added a line on Page 2 that shows which controller the page holds and whether it's closed. Same sequence on both builds (Ctrl+I, Ctrl+B, Ctrl+I 230ms later), then typing in the field:The tests are in
test/navigation/reopen_route_during_pop_test.dart. Three fail on master: reopening right away, reopening 150ms into the pop, and checking that the reopened page's controller is deleted when that page closes (so nothing leaks). The fourth checks that a normal pop still deletes the controller.All 226 tests pass on Flutter 3.47.8 and 3.50.0.
Pre-launch Checklist
///). No public API changes.